<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/26
  Time: 9:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生信息管理系统</title>
  <link rel="stylesheet" href="/css/student.css">
  <style>
    h3 {
      text-align: center;
    }
  </style>
</head>
<body>
  <h3>学生信息管理系统</h3>
  <div>
    <form action="${pageContext.request.contextPath}/student/condition" method="post">
      <span>查询条件：</span>
      <input name="condition" placeholder="请输入要查询的信息（姓名或性别）" style="width: 250px; height: 25px">
      <input type="submit" value="模糊搜索">
      <a href="/student/add.jsp" style="margin-left: 750px">添加信息</a>
    </form>
  </div>

  <div>
    <c:if test="${empty students}">
      数据不存在
    </c:if>
    <c:if test="${students != null}">
      <table>
        <tr>
          <th>学生编号</th>
          <th>学生姓名</th>
          <th>学生性别</th>
          <th>学生年龄</th>
          <th>学生分数</th>
          <th>入学时间</th>
          <th>操作功能</th>
        </tr>
        <c:forEach var="stu" items="${students}">
          <tr>
            <td>${stu.no}</td>
            <td>${stu.name}</td>
            <td>${stu.sex}</td>
            <td>${stu.age}</td>
            <td>${stu.score}</td>
            <td>${stu.time}</td>
            <td>
              <a href="${pageContext.request.contextPath}/student/del?no=${stu.no}" class="del"> 删除</a>
              ||
              <a href="${pageContext.request.contextPath}/student/update?no=${stu.no}">修改</a>
            </td>
          </tr>
        </c:forEach>
      </table>
    </c:if>
  </div>

<script>
  // js 最基本的写法
  document.querySelector(".del").addEventListener("click", (e) => {
    if (!confirm("是否要删除它？")) {
      e.preventDefault();
    }
  })
</script>
</body>
</html>
